<?php
require("connect.inc.php");

function addReadLog($channelId,$username){
	global $db;
	$ip=getIP();
	
	$sql = "LOCK TABLES readlog WRITE";
	$db->sql_query($sql);
	
	if($username==""||$username==null)
		$sql="insert into readlog (channelId,ip) Value('$channelId','$ip')";
	else
		$sql="insert into readlog (channelId,username,ip) Value('$channelId','$username','$ip')";
	$db->sql_query($sql);
	
	$sql = "UNLOCK TABLES";
	$db->sql_query($sql);
}

function getIP(){
	if (getenv(HTTP_X_FORWARDED_FOR)) {							
		$ip = getenv(HTTP_X_FORWARDED_FOR); 
	} else { 
		$ip = getenv(REMOTE_ADDR);
	}	
	return $ip;
}
?>